package com.cy.dda.web.admin.org;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cy.dda.model.PageBean;
import com.cy.dda.model.Result;
import com.cy.dda.model.ao.org.OrgAddAO;
import com.cy.dda.model.domain.org.Org;
import com.cy.dda.model.query.org.OrgListAdminQuery;
import com.cy.dda.model.vo.org.OrgListAdminVO;
import com.cy.dda.service.org.OrgService;
import com.cy.dda.web.BaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 后台-委托机构管理
 *
 * @author: tanyilin
 * @create: 2018年11月7日 上午10:12:25
 */
@Slf4j
@RestController
@RequestMapping("/admin/org")
@Api(tags = "后台-委托机构管理")
public class AdminOrgController extends BaseController {

	@Autowired
	private OrgService orgService;
	
	@ApiOperation("机构列表")
	@GetMapping("/list")
	public PageBean<OrgListAdminVO> list(OrgListAdminQuery query) {
		PageBean<OrgListAdminVO> pageBean = orgService.selectOrgListAdmin(query);
		return pageBean;
	}
	
	@ApiOperation("新增")
	@PostMapping("/do/add")
	public Result doAdd(@Validated OrgAddAO addAO, BindingResult bindingResult) {
		this.checkError(bindingResult);
		Org org = new Org();
		BeanUtils.copyProperties(addAO, org);
		orgService.addOrg(org);
		return ok();
	}
	
	@ApiOperation("全部机构列表数组")
	@GetMapping("/get/all/list")
	public Result<List<Org>> getAllList() {
		List<Org> list = orgService.selectAllOrgList();
		return ok("", list);
	}
	
}
